home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume11 / dialout / part01 next >
Encoding:
Text File  |  1990-03-11  |  14.4 KB  |  515 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v11i025: dialout -- another kill getty and kermit prog
  3. From: nelson@uncecs.edu@uncw.uucp (Jim Nelson)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 11, Issue 25
  7. Submitted-by: nelson@uncecs.edu@uncw.uucp (Jim Nelson)
  8. Archive-name: dialout/part01
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of shell archive."
  17. # Contents:  README dialout.1 Makefile dialout.c avatex.h courier.h
  18. #   avatex.data courier.data
  19. # Wrapped by nelson@uncw on Sun Mar 11 15:58:35 1990
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'README' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'README'\"
  23. else
  24. echo shar: Extracting \"'README'\" \(841 characters\)
  25. sed "s/^X//" >'README' <<'END_OF_FILE'
  26. XA program to kill the [getty|uugetty] on a terminal line,
  27. Xand bring up a "kermit" on that line.  If the kermit is
  28. Xshut down garacefully, the [getty|uugetty] is restarted.
  29. XAttempts to gracefully interface with uucp and kermit
  30. Xvia the "standard" lockfiles (your mileage in this regard
  31. Xmay vary).  Works (has worked) with BSD 4.2 and SysVR3.
  32. XYour luck with having a uugetty behave rationally with
  33. Xkermit and/or uucp is problematical.
  34. XTo install: edit avatex.h and courier.h to reflect your
  35. X"tty" lines.  Then edit Makefile to reflect your system.
  36. XThen "make".  Then (you'll have to go root here) "make install".
  37. XYou must be root to install this program, and it must run
  38. Xsuid root (lockfile stuff, etc.).  Examine the source carefully
  39. Xif you are wary of suid root programs.
  40. XPublic domain.
  41. X-- jim nelson, unc-wilmington, nelson@ecsvax.uncecs.edu
  42. END_OF_FILE
  43. if test 841 -ne `wc -c <'README'`; then
  44.     echo shar: \"'README'\" unpacked with wrong size!
  45. fi
  46. # end of 'README'
  47. fi
  48. if test -f 'dialout.1' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'dialout.1'\"
  50. else
  51. echo shar: Extracting \"'dialout.1'\" \(400 characters\)
  52. sed "s/^X//" >'dialout.1' <<'END_OF_FILE'
  53. X.TH DIALOUT 1 Local
  54. X.UC 4
  55. X.SH NAME
  56. Xdialout \- kill getty and bring up kermit on modem
  57. X.SH SYNOPSIS
  58. X.B dialout
  59. X.SH DESCRIPTION
  60. XShuts down the getty and brings up Kermit on the 1200 baud
  61. Xcourier modem line (/dev/ttyd8).
  62. X.SH NOTES
  63. XThe user should be familiar with the AT command set for the
  64. Xparticular modem in use (Courier 1200, in this case).
  65. X.SH AUTHOR
  66. XJ. Nelson, UNCW, BSD 21 Apr 89, SysV 11 Mar 90
  67. END_OF_FILE
  68. if test 400 -ne `wc -c <'dialout.1'`; then
  69.     echo shar: \"'dialout.1'\" unpacked with wrong size!
  70. fi
  71. # end of 'dialout.1'
  72. fi
  73. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  74.   echo shar: Will not clobber existing file \"'Makefile'\"
  75. else
  76. echo shar: Extracting \"'Makefile'\" \(1230 characters\)
  77. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  78. XCFLAGS=
  79. XSYS=SYSV#BSD
  80. X
  81. X#/*where to install this thing*/
  82. XWHERE=/usr/local/bin
  83. X
  84. Xall: dirs dial2400 dialout
  85. X
  86. Xdialout: dialout.o
  87. X    cp courier.h courier/dialout.h
  88. X    cc -s -o dialout dialout.o
  89. X
  90. Xdial2400: dial2400.o
  91. X    cp avatex.h avatex/dialout.h
  92. X    cc -s -o dial2400 dial2400.o
  93. X
  94. Xdialout.o: dialout.c courier.h
  95. X    cp courier.h courier/dialout.h
  96. X    cc -D$(SYS) -c -Icourier dialout.c
  97. X
  98. Xdial2400.o: dialout.c avatex.h
  99. X    rm -f dial2400.c
  100. X    cp avatex.h avatex/dialout.h
  101. X    ln dialout.c dial2400.c
  102. X    cc -D$(SYS) -c -Iavatex dial2400.c
  103. X
  104. Xinstall: dialout dial2400
  105. X    mv dialout $(WHERE)/dialout
  106. X    chown root $(WHERE)/dialout
  107. X    chmod u+s $(WHERE)/dialout
  108. X    mv dial2400 $(WHERE)/dial2400
  109. X    chown root $(WHERE)/dial2400
  110. X    chmod u+s $(WHERE)/dial2400
  111. X    cp avatex.data $(WHERE)/avatex.data
  112. X    cp courier.data $(WHERE)/courier.data
  113. X
  114. Xclean:
  115. X    rm -f dialout dial2400* *.i *.o
  116. X
  117. Xdirs: avatex courier avatex.h courier.h avatex.data courier.data
  118. X
  119. Xavatex:
  120. X    sh -c "if test -d avatex; then : ;else mkdir avatex;fi"
  121. X
  122. Xcourier:
  123. X    sh -c "if test -d courier; then : ;else mkdir courier;fi"
  124. X
  125. Xkit:
  126. X    cp avatex/dialout.h ./avatex.h
  127. X    cp $(WHERE)/avatex.data ./avatex.data
  128. X    cp courier/dialout.h ./courier.h
  129. X    cp $(WHERE)/courier.data ./courier.data
  130. X    shar README *1 Makefile dialout.c *.h *.data>kit
  131. END_OF_FILE
  132. if test 1230 -ne `wc -c <'Makefile'`; then
  133.     echo shar: \"'Makefile'\" unpacked with wrong size!
  134. fi
  135. # end of 'Makefile'
  136. fi
  137. if test -f 'dialout.c' -a "${1}" != "-c" ; then 
  138.   echo shar: Will not clobber existing file \"'dialout.c'\"
  139. else
  140. echo shar: Extracting \"'dialout.c'\" \(4936 characters\)
  141. sed "s/^X//" >'dialout.c' <<'END_OF_FILE'
  142. X/* program to kill getty & bring up kermit on a tty line*/
  143. X/* probably dynix specific ... don't know, don't care */
  144. X/* j. nelson, (nelson@uncw.uucp) (nelson@ecsvax.uncecs.edu) */
  145. X/* latest revision 
  146. XSat Mar 10 15:32:08 EST 1990
  147. X*/
  148. X#include <stdio.h>
  149. X#include <fcntl.h>
  150. X#include <pwd.h>
  151. X#include <sys/types.h>
  152. X#include <sys/stat.h>
  153. X
  154. X#include "dialout.h"
  155. X/* the dialout.h files should be in specific subdirectories, e.g.*/
  156. X/*avatex, courier, etc. */
  157. Xmain(argc,argv)char *argv[];
  158. X{
  159. X    int i,fd; 
  160. X        unsigned long t;
  161. X    FILE *fp;
  162. X    char buf[120], name[12], *strncpy();
  163. X    struct passwd *p, *getpwuid();
  164. X    char *q, *getlogin();
  165. X
  166. X    (void)argc;
  167. X    (void)argv; /*strictly for lint*/
  168. X    q=getlogin();
  169. X    if(!authorized(q)){
  170. X        fprintf(stderr,"%s not authorized to dialout\n",q);
  171. X        exit(1);
  172. X        }
  173. X    {
  174. X        fp=fopen("/tmp/dialoutlog","a");
  175. X        if(!fp)exit(2);
  176. X        t=time(0);
  177. X        fprintf(fp," + %s %s",q,ctime(&t));
  178. X        fclose(fp);
  179. X
  180. X    }
  181. X    if(geteuid()!=0){
  182. X        fprintf(stderr,"oops, this prog should be setuid root\n");
  183. X        error(1);
  184. X    }
  185. X    fiddle();
  186. X    p = getpwuid(getuid());
  187. X    (void)strncpy(name,p->pw_name,11);
  188. X    for(i=0;i<12;i++)if(name[i]<' ' || name[i]>0176)name[i]=0;
  189. X    fprintf(stderr,"%s\n",name);
  190. X    if(stat(LCKFILE,(struct stat *)0)>=0)
  191. X    {
  192. X        fd=open(LCKFILE,0);
  193. X        if(fd>=0){
  194. X            fprintf(stderr,"oops\n");
  195. X            fprintf(stderr,"%s busy\n",LCKFILE);
  196. X            i=read(fd,buf,11);
  197. X            if(i>0)fprintf(stderr,"by %s ... try later\n",buf);
  198. X            error(2);
  199. X        }
  200. X    }
  201. X    else {
  202. X        fprintf(stderr,"ok no lock\n");
  203. X    }
  204. X    (void)system(SED1);
  205. X/*    (void)system("    diff /etc/ttys /tmp/dialout.tmp");*/
  206. X    (void)system(DIFF1);
  207. X/*    (void)system("    cp /etc/ttys /etc/ttys.bak.tst");*/
  208. X    (void)system(CP1);
  209. X/*    (void)system("    cp /tmp/dialout.tmp /etc/ttys");*/
  210. X    (void)system(CP2);
  211. X    i=kill(1,1); /*kill(pid,signal)*/
  212. X    if(i<0){
  213. X        fprintf(stderr,"could not kill(1,1)\n");
  214. X        error(3);
  215. X    }
  216. X    (void)system("    rm -f /tmp/dialout.tmp" );
  217. X    fd=open(DEVICE,1);
  218. X    if(fd<0){
  219. X        error(4);
  220. X    }
  221. X    i=write(fd,S1,S1L);
  222. X    if(i<0)error(5);
  223. X    sleep(1);
  224. X    (void)system(CAT);
  225. X
  226. X    fiddle();
  227. X/*    i=fchown(fd,getuid(),getgid());*/
  228. X/* apparently SysV does not have fchown() nor fchmod() :-(  */
  229. X    i=chown(DEVICE,getuid(),getgid());
  230. X    if(i<0)error(6);
  231. X/*    i=fchmod(fd,0666);*/
  232. X    i=chmod(DEVICE,0666);
  233. X    if(i<0)error(7);
  234. X    i=close(fd);
  235. X    if(i<0)error(8);
  236. X
  237. X    if(fork()==0)
  238. X    {
  239. X        /*child*/
  240. X        i=setuid(getuid());/*relinquish root privileges in child*/
  241. X        if(i<0 || geteuid()==0)error(9);
  242. X        fprintf(stderr,"PLEASE exit from kermit normally so that\n");
  243. X        fprintf(stderr,"the modem line can be reset properly.\n");
  244. X        fprintf(stderr,
  245. X        "The proper way is ctrl-\\, then \"c\", then \"ex\"\n");
  246. X
  247. X        (void)execl(KERMIT,"kermit","-l",DEVICE,
  248. X        "-b",SPEED,(char *)NULL);
  249. X        fprintf(stderr,"exec failed\n");/*should never happen*/
  250. X        error(10);/*should never happen*/
  251. X    }
  252. X    else
  253. X    {
  254. X        /*parent*/
  255. X        /* (parent is still root) */
  256. X        (void)wait(0);
  257. X        fd=open(DEVICE,1);
  258. X        if(fd<0){
  259. X            error(11);
  260. X        }
  261. X        i=write(fd,S2,S2L);
  262. X        if(i<0)error(12);
  263. X        fprintf(stderr,"wait...\n");
  264. X        sleep(2);
  265. X/*    i=fchown(fd,0,0);*/
  266. X    i=chown(DEVICE,0,0);
  267. X    if(i<0)error(6);
  268. X/*    i=fchmod(fd,0666);*/
  269. X    i=chmod(DEVICE,0666);
  270. X    if(i<0)error(7);
  271. X        i=close(fd);
  272. X        if(i<0)error(13);
  273. X        (void)unlink(LCKFILE); /*ignore error, because kermit didit*/
  274. X        (void)system(SED2);
  275. X
  276. X/*        (void)system("    diff /etc/ttys /tmp/dialout.tmp");*/
  277. X        (void)system(DIFF2);
  278. X/*        (void)system("    cp /tmp/dialout.tmp /etc/ttys");*/
  279. X        (void)system(CP3);
  280. X        i=kill(1,1); /*kill(pid,signal)*/
  281. X        if(i== -1){
  282. X            fprintf(stderr,"could not kill(1,1)\n");
  283. X            if(getuid()!=0 && getuid()!=100)error(14);
  284. X        }
  285. X        (void)system("    rm -f /tmp/dialout.tmp" );
  286. X
  287. X    
  288. X        fp=fopen("/tmp/dialoutlog","a");
  289. X        if(!fp)exit(2);
  290. X        t=time(0);
  291. X        fprintf(fp," - %s %s",q,ctime(&t));
  292. X        fclose(fp);
  293. X
  294. X    
  295. X    }
  296. X}
  297. Xfiddle()
  298. X{
  299. X    struct passwd *p;
  300. X    struct stat zork;
  301. X    int i,c;
  302. X    i=stat(DEVICE,&zork);
  303. X    if(i<0)error(15);
  304. X    if(zork.st_uid != 0){
  305. X        p=getpwuid(zork.st_uid);
  306. X        fprintf(stderr,
  307. X        "the modem seems to be owned by %s\n",/*zork.st_uid*/p->pw_name);
  308. X        fprintf(stderr,"do you wish to barge right on through?");
  309. X        c=getchar(); while(getchar()!='\n');
  310. X        if(c!='y')error(16);
  311. X    }
  312. X    if((zork.st_mode & 0777) != 0622){
  313. X        fprintf(stderr,"%s has wrong mode\n",DEVICE);
  314. X        fprintf(stderr,"do you wish to barge right on through?");
  315. X        c=getchar(); while(getchar()!='\n');
  316. X        if(c!='y')error(17);
  317. X    }
  318. X}
  319. Xerror(i)
  320. X{
  321. X    FILE *fp;
  322. X    char *q;
  323. X    unsigned long t;
  324. X    fprintf(stderr,"error %d\n",i);
  325. X    (void)fflush(stderr);
  326. X        fp=fopen("/tmp/dialoutlog","a");
  327. X        if(!fp)exit(2);
  328. X        t=time(0);
  329. X        q=getlogin();
  330. X        fprintf(fp," - error %d %s %s",i,q,ctime(&t));
  331. X        fclose(fp);
  332. X    exit(i);
  333. X}
  334. Xkindex(s,t) 
  335. Xchar s[],t[];
  336. X{
  337. X    int c,i,j,k;
  338. X    c=s[0];
  339. X    if(c==0){return -1;
  340. X        }
  341. X    c=t[0];
  342. X    if(c==0){return -1;
  343. X        }
  344. X    for(i=0;s[i] !='\0'; i++){
  345. X        for(j=i,k=0;t[k] !='\0' && s[j]==t[k];j++,k++)
  346. X                ;
  347. X        if(t[k]=='\0')return (i);
  348. X    }
  349. X        return(-1);
  350. X} 
  351. Xauthorized(name)
  352. Xchar *name;
  353. X{
  354. X    FILE *fp;
  355. X    int k;
  356. X    char buf[99];
  357. X    fp=fopen(AUTHFILE,"r");
  358. X    if(!fp)return 0;
  359. X    while( fgets(buf,98,fp)==buf){
  360. X    if(kindex(buf,name)==0){
  361. X        fclose(fp);
  362. X        return 1;
  363. X    }
  364. X    }
  365. X    fclose(fp);
  366. X    return 0;
  367. X
  368. X}
  369. END_OF_FILE
  370. if test 4936 -ne `wc -c <'dialout.c'`; then
  371.     echo shar: \"'dialout.c'\" unpacked with wrong size!
  372. fi
  373. # end of 'dialout.c'
  374. fi
  375. if test -f 'avatex.h' -a "${1}" != "-c" ; then 
  376.   echo shar: Will not clobber existing file \"'avatex.h'\"
  377. else
  378. echo shar: Extracting \"'avatex.h'\" \(1200 characters\)
  379. sed "s/^X//" >'avatex.h' <<'END_OF_FILE'
  380. X#define LCKFILE "/usr/spool/uucp/LCK/LCK..ttyh0"
  381. X#define KERMIT "/usr/uncw/kermit" /*where you keep your kermit*/
  382. X#ifdef BSD
  383. X#define DEVICE "/dev/ttyh0"
  384. X#else
  385. X#define DEVICE "/dev/contty"
  386. X#endif
  387. X#define SPEED "2400"
  388. X#define S1 "ate1q0x4v1\015"
  389. X#define S2 "atz\015"
  390. X#define S1L strlen(S1)
  391. X#define S2L strlen(S2)
  392. X#ifdef BSD
  393. X#define SED1 "sed '/ttyh0/s/^1/0/' /etc/ttys >/tmp/dialout.tmp"
  394. X#define SED2 "sed '/ttyh0/s/^0/1/' /etc/ttys >/tmp/dialout.tmp"
  395. X#else
  396. X/*SysV*/
  397. X#define SED1 "sed '/^ct:/s/respawn/off/' /etc/inittab>/tmp/dialout.tmp"
  398. X#define SED2 "sed '/^ct:/s/off/respawn/' /etc/inittab>/tmp/dialout.tmp"
  399. X#endif
  400. X#define CAT "cat /usr/lib/uucp/avatex.data"
  401. X#define AUTHFILE "/etc/dialout.auth"
  402. X#ifdef BSD
  403. X#define DIFF1    "diff /etc/ttys /tmp/dialout.tmp"
  404. X#define CP1        "cp /etc/ttys /etc/ttys.bak.tst"
  405. X#define CP2        "cp /tmp/dialout.tmp /etc/ttys"
  406. X#define DIFF2    "diff /etc/ttys /tmp/dialout.tmp"
  407. X#define CP3        "cp /tmp/dialout.tmp /etc/ttys"
  408. X#else
  409. X#define DIFF1    "diff /etc/inittab /tmp/dialout.tmp"
  410. X#define CP1        "cp /etc/inittab /etc/ttys.bak.tst"
  411. X#define CP2        "cp /tmp/dialout.tmp /etc/inittab"
  412. X#define DIFF2    "diff /etc/inittab /tmp/dialout.tmp"
  413. X#define CP3        "cp /tmp/dialout.tmp /etc/inittab"
  414. X#endif
  415. END_OF_FILE
  416. if test 1200 -ne `wc -c <'avatex.h'`; then
  417.     echo shar: \"'avatex.h'\" unpacked with wrong size!
  418. fi
  419. # end of 'avatex.h'
  420. fi
  421. if test -f 'courier.h' -a "${1}" != "-c" ; then 
  422.   echo shar: Will not clobber existing file \"'courier.h'\"
  423. else
  424. echo shar: Extracting \"'courier.h'\" \(1200 characters\)
  425. sed "s/^X//" >'courier.h' <<'END_OF_FILE'
  426. X#define LCKFILE "/usr/spool/uucp/LCK/LCK..ttyh0"
  427. X#define KERMIT "/usr/uncw/kermit" /*where you keep your kermit*/
  428. X#ifdef BSD
  429. X#define DEVICE "/dev/ttyh8"
  430. X#else
  431. X#define DEVICE "/dev/contty"
  432. X#endif
  433. X#define SPEED "1200"
  434. X#define S1 "ate1q0x4v1\015"
  435. X#define S2 "atz\015"
  436. X#define S1L strlen(S1)
  437. X#define S2L strlen(S2)
  438. X#ifdef BSD
  439. X#define SED1 "sed '/ttyh0/s/^1/0/' /etc/ttys >/tmp/dialout.tmp"
  440. X#define SED2 "sed '/ttyh0/s/^0/1/' /etc/ttys >/tmp/dialout.tmp"
  441. X#else
  442. X/*SysV*/
  443. X#define SED1 "sed '/^ct:/s/respawn/off/' /etc/inittab>/tmp/dialout.tmp"
  444. X#define SED2 "sed '/^ct:/s/off/respawn/' /etc/inittab>/tmp/dialout.tmp"
  445. X#endif
  446. X#define CAT "cat /usr/lib/uucp/avatex.data"
  447. X#define AUTHFILE "/etc/dialout.auth"
  448. X#ifdef BSD
  449. X#define DIFF1    "diff /etc/ttys /tmp/dialout.tmp"
  450. X#define CP1        "cp /etc/ttys /etc/ttys.bak.tst"
  451. X#define CP2        "cp /tmp/dialout.tmp /etc/ttys"
  452. X#define DIFF2    "diff /etc/ttys /tmp/dialout.tmp"
  453. X#define CP3        "cp /tmp/dialout.tmp /etc/ttys"
  454. X#else
  455. X#define DIFF1    "diff /etc/inittab /tmp/dialout.tmp"
  456. X#define CP1        "cp /etc/inittab /etc/ttys.bak.tst"
  457. X#define CP2        "cp /tmp/dialout.tmp /etc/inittab"
  458. X#define DIFF2    "diff /etc/inittab /tmp/dialout.tmp"
  459. X#define CP3        "cp /tmp/dialout.tmp /etc/inittab"
  460. X#endif
  461. END_OF_FILE
  462. if test 1200 -ne `wc -c <'courier.h'`; then
  463.     echo shar: \"'courier.h'\" unpacked with wrong size!
  464. fi
  465. # end of 'courier.h'
  466. fi
  467. if test -f 'avatex.data' -a "${1}" != "-c" ; then 
  468.   echo shar: Will not clobber existing file \"'avatex.data'\"
  469. else
  470. echo shar: Extracting \"'avatex.data'\" \(7 characters\)
  471. sed "s/^X//" >'avatex.data' <<'END_OF_FILE'
  472. XHayes?
  473. END_OF_FILE
  474. if test 7 -ne `wc -c <'avatex.data'`; then
  475.     echo shar: \"'avatex.data'\" unpacked with wrong size!
  476. fi
  477. # end of 'avatex.data'
  478. fi
  479. if test -f 'courier.data' -a "${1}" != "-c" ; then 
  480.   echo shar: Will not clobber existing file \"'courier.data'\"
  481. else
  482. echo shar: Extracting \"'courier.data'\" \(777 characters\)
  483. sed "s/^X//" >'courier.data' <<'END_OF_FILE'
  484. Xc0=transmitter disabled, c1=transmitter enabled
  485. Xd p=pulse, t=tone, ','=pause 2 sec, ';'=return to command state
  486. X  !=flash hook, w=wait for 2nd dialtone (x3 or higher)
  487. X  @=wait for answer (x3 or higher), r=reverse roles
  488. Xe0=echo off, e1=echo on
  489. Xf0=half duples, f1=full duples
  490. Xh0=hang up, h1=go off hook
  491. Xi0=product code, i1=rom cksum, i2=ram test, i3=return call duration/
  492. X   real time, i4=display current settings
  493. Xk0=at ati3 display call duration, k1=real time
  494. Xm0=speaker off, m1=speaker on until connect, m2=always on
  495. Xo=return online
  496. Xp=pulse dial
  497. Xq0=result codes displayed, q1=quiet mode
  498. Xv0=numeric mode, v1=verbal mode
  499. Xx0-6=verbosity level(6 is most verbose)
  500. Xz=reset to default
  501. X>=repeat command continuously
  502. X$=help command summary
  503. XD$=dial help commands
  504. Xs$=s-reg help commands
  505. X
  506. END_OF_FILE
  507. if test 777 -ne `wc -c <'courier.data'`; then
  508.     echo shar: \"'courier.data'\" unpacked with wrong size!
  509. fi
  510. # end of 'courier.data'
  511. fi
  512. echo shar: End of shell archive.
  513. exit 0
  514.  
  515.